package propertiesio;

import java.util.Map;
import java.util.Properties;
import java.util.Set;

public class PropertiesDemo1 {
    public static void main(String[] args) {
        Properties prop = new Properties();
        // 增
        prop.put("小龙女", "尹志平");
        prop.put("张三", "李四");
        prop.put("罗志祥", "范德萨");
        System.out.println(prop);

        // 删
        prop.remove("张三");
        System.out.println(prop);

        // 改
        // put ---如果键不存在,那么就添加,如果键存在,那么就覆盖
        prop.put("小龙女", "李四");
        System.out.println(prop);

        // 查
        System.out.println(prop.get("罗志祥"));

        System.out.println("-------------");
        // 遍历(键)
        Set<Object> keys = prop.keySet();
        for (Object key : keys) {
            System.out.println(key + "=" + prop.get(key));
        }
        System.out.println("-------------");
        // 键值对对象
        Set<Map.Entry<Object, Object>> entries = prop.entrySet();
        for (Map.Entry<Object, Object> entry : entries) {
            System.out.println(entry.getKey() + "=" + entry.getValue());
        }

    }
}
